$(function() {
	$("#task-file-list-correct").on("click","#deleteFile",function() {
		var key = $('input[name="answerAttachKey"]').val();
		$.post(CONTEXT_PATH+"resource/deleteFile?key="+key, function(data) {
			if(data.status=="success"){
				//layer.msg("服务器端删除成功");
			}else{
				//layer.msg("服务器端删除失败");
			}
		});		
		$(this).closest("li").remove();
		return false;
	});
	//确认重传
	$("#ensure-to-reupload").click(function() {
		$("#ensure-to-reupload-layer").modal("show");
	});
	
	$("#cancel").click(function() {
		$("#ensure-to-reupload-layer").modal("hide");
	});
	
	/* 预览图片 */
	$("#task-file-list-correct").delegate(".imgview","click",function(){
		showImg($(this));
	});
	
	//show img in reply of task submit
	//TODO:需要解决有多个img情况下共用一个degr导致的选择角度的跳跃情况
	var degr = 0;
	$("#replyAnswer").delegate("img","click",function(){
		degr += 90;
		$(this)[0].style.transform = "rotate(" + degr + "deg)";
	});
});

//show img in attachment of task submit
var showImg = function(a){
	if(a.text() =="预览"){
		a.text("收起");
	}else{
		a.text("预览");
	}
	var index = a.attr("id").replace(/showimage-/,"");
	if($("*[id$='imgView-"+index+"']")[0].style.display=="none"){
		$("*[id$='imgView-"+index+"']").show();
		var deg = 0;
		document.getElementById("imgView-"+index).onclick = function () {
			deg += 90;
			document.getElementById("imgView-"+index).style.transform = "rotate(" + deg + "deg)";
		}
	}
	else{
		$("*[id$='imgView-"+index+"']").hide();
	}
}